package net.anzhuo.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import net.anzhuo.common.entity.PaginationVO;
import net.anzhuo.common.enums.ResultEnum;
import net.anzhuo.common.utils.ExceptionUtil;
import net.anzhuo.dao.GsCompanyProductsMapper;
import net.anzhuo.entity.GsCompanyProducts;
import net.anzhuo.service.GsCompanyProductsService;
@Service
public class GsCompanyProductsServiceImpl implements GsCompanyProductsService {

	@Autowired
	private GsCompanyProductsMapper gsCompanyProductsMapper;
	
	@Override
	public GsCompanyProducts getById(Long id) {
		// TODO Auto-generated method stub
		
		return gsCompanyProductsMapper.getById(id);
	}

	@Override
	public List<GsCompanyProducts> getBycoMd5(String coMd5) {
		// TODO Auto-generated method stub
		return gsCompanyProductsMapper.getBycoMd5(coMd5);
	}

	@Override
	public PaginationVO<GsCompanyProducts> getListWithPage(GsCompanyProducts gsCheck) {
		PaginationVO<GsCompanyProducts> paginationVO = new PaginationVO<>();
		paginationVO.setList(gsCompanyProductsMapper.getListWithPage(gsCheck));
		paginationVO.setTotalCount(gsCompanyProductsMapper.getCount(gsCheck));
		paginationVO.setTotalPage((gsCompanyProductsMapper.getCount(gsCheck) + gsCheck.getPageSize() -1)  / gsCheck.getPageSize());
		paginationVO.setPageNo(gsCheck.getPageNo());
		return paginationVO;
	}

	@Override
	public List<GsCompanyProducts> getList() {
		// TODO Auto-generated method stub
		return  gsCompanyProductsMapper.getList();
	}

	@Override
	public List<GsCompanyProducts> getList(GsCompanyProducts gsCheck) {
		// TODO Auto-generated method stub
		return gsCompanyProductsMapper.getListByQuery(gsCheck);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void update(GsCompanyProducts gsCheck) {
		// TODO Auto-generated method stub
		gsCompanyProductsMapper.update(gsCheck);

	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void save(GsCompanyProducts gsCheck) {
		// TODO Auto-generated method stub
		gsCompanyProductsMapper.save(gsCheck);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void delete(Long id) {
		GsCompanyProducts gsCheck = gsCompanyProductsMapper.getById(id);
		if (gsCheck == null) {
			ExceptionUtil.throwAppException(ResultEnum.ILLEGAL_OPERATION);
			return;
		}
		gsCompanyProductsMapper.update(gsCheck);

	}

}
